#include <stdio.h>
#include <unistd.h>
#include <e_file.h>
#include <string.h>

int main (int argc, char **argv)
{
	char *msg = "this is a test....\n";
	int fd = open (argv[1], O_WRONLY|O_CREAT|O_TRUNC, 0664);
	printf ("fd = %d\n", fd);
	if (fd == -1) {
		perror ("open()");
		return -1;
	}
	//保护现场
	int s_fd = dup(1);
	dup2 (fd, 1);
	close (fd);
	write (1, msg, strlen(msg));
	//恢复现场
	dup2 (s_fd, 1);
	close (s_fd);
	write (1, msg, strlen(msg));
		
	return 0;
}
